<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.title.center_jueseManage"></spring:message></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1>角色管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">角色管理</a></li>
            <li class="active"><a href="#">角色管理</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                    <div class="textalign1"><spring:message code="message.lable.jueseName"></spring:message><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <input type="text" class="textinput"  id="name" placeholder="<spring:message code="message.lable.jueseName"></spring:message>" maxlength="50" />
                    </div>
                    <div class="textalign" >
                    <ms:btn url="/sysRole/getZxRoleList.html"><button type="button" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"></spring:message></button></ms:btn>
                	<button id="addRoleBtn" type="button" class="btn btn-success btn-sm" onclick="addRoleModal();">新 增</button>
                </div>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        
        
        <div class="modal fade" id="addRoleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h5 class="modal-title">新增角色</h5>
					</div>
                 <form class="form-horizontal"  action="addRole.html" id="addForm" method="post">
					<div class="modal-body">
						<div class="form-group form-group-xs">
	                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>角色名称：</label>
	                        <div class="col-sm-6 text-left">
	                            <input class="form-control" id="rolename" name="name" value="" placeholder="角色名称" type="text">
	                        </div>
	                    </div>
	                    <div class="form-group form-group-xs">
	                        <label for="remark" class="col-sm-2 text-right"><spring:message code="message.lable.remarkSpacing"/><spring:message code="message.yanZheng.maoHao"/></label>
	                        <div class="col-sm-9">
	                            <textarea class="form-control" id="addremark" name="remark" rows="5" placeholder="<spring:message code="message.lable.remarkSpacing"/>" maxlength="500"></textarea>
	                        </div>
                   		</div>
					</div>
					</form>
					<div class="modal-footer">
						 <button type="button" class="btn btn-primary btn-sm" onclick="addRole();"><spring:message code="message.button.saveSpacing"/></button>
						<button type="button" class="btn btn-danger btn-sm" id="closeChangePasswordDialog" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
					</div>
				</div>
			</div>
		</div>
		
		<div class="modal fade" id="editRoleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h5 class="modal-title">新增角色</h5>
					</div>
                 <form class="form-horizontal"  action="eidtRole.html" id="editForm" method="post">
                 <input type="hidden" id="editid" name="id">
					<div class="modal-body">
						<div class="form-group form-group-xs">
	                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>角色名称：</label>
	                        <div class="col-sm-6 text-left">
	                            <input class="form-control" id="editrolename" name="name" value="" placeholder="角色名称" type="text">
	                        </div>
	                    </div>
	                    <div class="form-group form-group-xs">
	                        <label for="remark" class="col-sm-2 text-right"><spring:message code="message.lable.remarkSpacing"/><spring:message code="message.yanZheng.maoHao"/></label>
	                        <div class="col-sm-9">
	                            <textarea class="form-control" id="editremark" name="remark" rows="5" placeholder="<spring:message code="message.lable.remarkSpacing"/>" maxlength="500"></textarea>
	                        </div>
                   		</div>
					</div>
					</form>
					<div class="modal-footer">
						 <button type="button" class="btn btn-primary btn-sm" onclick="editRole();"><spring:message code="message.button.saveSpacing"/></button>
						<button type="button" class="btn btn-danger btn-sm" id="closeChangePasswordDialog" data-dismiss="modal"><spring:message code="message.button.closeSpacing"/></button>
					</div>
				</div>
			</div>
		</div>
		
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    function modifyRoleModal(id, name, remark){
    	$('#editForm')[0].reset();  
    	$("#editid").val(id);
    	$("#editrolename").val(name);
    	$("#editremark").val(remark);
		$('#editRoleModal').modal({
            keyboard: true
        });
    }
    
    
    function addRoleModal() {
 		$('#addForm')[0].reset();  
		$('#addRoleModal').modal({
            keyboard: true
        });
		
	}
    function editRole(){
		 if ($.trim($("#editrolename").val()).length < 1){
			 $.HN.message.alert("角色名称不能为空！", "warn");
			 return;
		 }
		 $.HN.message.confirm("确定要修改角色？", '', '').on(function (e) {
             if (e) {
          		$("#editForm").ajaxSubmit({
       			dataType : "json",
       			timeout: 10000,
       			success : function(result, statusText) {
       				if (result.success) {
       					    $('#editRoleModal').modal('hide');
       					    search( $("#gridlist").getGridParam("page"));
       					    top.$.HN.message.alert("<spring:message code='message.HN.alert.success'/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code='message.HN.alert.type'/>", "success");
       				} else {
       					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
       				}
       			}
       		});
   		}
      	  });
	 }
    
    function deleteRole(id,name){
    	$.HN.message.confirm("确定要删除<b>"+name+"</b>角色？", '', '').on(function (e) {
             if (e) {
            	 $.ajax({
                     url: "${pageContext.request.contextPath}/sysRole/deleteRole.html",//action地址
                     data: { "id":id},//传值
                     type: "post",//执行方式get or post 默认以post方式执行
                     dataType:"json",
                     success: function (result) {//执行成功后 提示
                         if (result.success){
                        	 top.$.HN.message.alert("<spring:message code='message.HN.alert.success'/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code='message.HN.alert.type'/>", "success");
                        	 search($("#gridlist").jqGrid('getGridParam','page'));
                        } else {
                        	$.HN.message.alert("删除失败！", "<spring:message code='message.HN.alert.type'/>", "error");
                        }
                     }
                 });
   		}
      	  });
    }
    
    function addRole(){
		 if ($.trim($("#rolename").val()).length < 1){
			 $.HN.message.alert("角色名称不能为空！", "warn");
			 return;
		 }
		 $.HN.message.confirm("确定要新增角色？", '', '').on(function (e) {
            if (e) {
         		$("#addForm").ajaxSubmit({
      			dataType : "json",
      			timeout: 10000,
      			success : function(result, statusText) {
      				if (result.success) {
      					    $('#addRoleModal').modal('hide');
      					    search( $("#gridlist").getGridParam("page"));
      					    top.$.HN.message.alert("<spring:message code='message.HN.alert.success'/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code='message.HN.alert.type'/>", "success");
      				} else {
      					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
      				}
      			}
      		});
  		}
     	  });
	 }
    
    
    
    
    	function search(page) {
    		var name = $.trim($("#name").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        	"name":name
    	        },
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	
    	function mainRolePrivilege(id,name){
    		$.HN.dialog.open({
	    		id:id,
	    		title:name,
	    		url:"${ctx}/sysPrivilege/mainRolePrivilege.html?roleId="+id,
	    		width:"800px",
	    		height:"550px",
	    		closefunc:function(){
	    		    // search();
	    		}
    		});
    	}
    	
    	// 临时用，发布时注释掉主角色的权限管理功能
    	function mainRolePrivilegeTemp(id,name){
            $.HN.dialog.open({
                id:id,
                title:name,
                url:"${ctx}/sysPrivilege/mainRolePrivilegeTemp.html?roleId="+id,
                width:"800px",
                height:"550px",
                closefunc:function(){
                    // search();
                }
            });
        }
    
        $(function () {
        	$('#name').focus();
            $("#gridlist").jqGrid({
                url: "getZxRoleList.html",
                mtype: "post",
                postData:{"main":1, "pid":"0"},
                datatype: "json",
                autowidth: true,
                height: 340,
                colNames: [
                    '<spring:message code="message.jqGrid.cz"/>',
					'<spring:message code="message.lable.jueseName"></spring:message>', 
					'<spring:message code="message.lable.remark"></spring:message>' 
                ],
                colModel: [
				    { name: 'operate', width:5, align:"center", sortable: false,
				        formatter : function(val, opts, rowdata) {
				        	 //var str = "<ms:btn url='/sysPrivilege/mainRolePrivilege.html'><a href='javascript:mainRolePrivilege(\""+rowdata.id+"\",\""+rowdata.name+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px -20px' class='opIcon' title='<spring:message code='message.label.privLook' />'></a></ms:btn>";
				             var str = "<a href='javascript:mainRolePrivilegeTemp(\""+rowdata.id+"\", \""+rowdata.name+"\");'>权限管理</a>";
				             str += "<a href='javascript:modifyRoleModal(\""+rowdata.id+"\", \""+rowdata.name+"\", \""+rowdata.remark+"\");'>修改</a>";
				             str += "<a href='javascript:deleteRole(\""+rowdata.id+"\", \""+rowdata.name+"\");'>删除</a>";
				            return str;
				        }
				    },
                    { name: 'name', width: 9, align:"center", sortable: false},
                    { name: 'remark', width: 12, align:"center", sortable: false}
                    
                ],
                rowNum: 10,
                rowList: [10, 20, 30],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "<spring:message code="message.title.center_jueseManage"></spring:message>",
                jsonReader: {
                    id: "id"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
    </script>
</body>
</html>












